<div id="wrapper">
    <div>
        <?php echo $this->form ?>
        <span id="form_message" style="color: red"><?php echo $this->formResponse ?></span>
    </div>
    <a href="<?php echo $this->url(array('module' => 'inscription'), 'default', true) ?>"><?php echo $this->translator->_('Register') ?></a>

    <!-- Sert à tester l'autocomplétion -->
    <br/><br/><br/><br/>
    <h2>Autocompletion jQuery</h2>
    <label for="citySearch">Ville :</label>
    <?php echo $this->formText('citySearch', ''); ?>
</div>

<script type="text/javascript" src="<?php echo $this->baseUrl ?>/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/js/zendtremplin_functions.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl ?>/js/jquery-ui-1.8.18.custom.min"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $("form").submit(function(){
            var loginVal = $("#login").val();
            var pwdVal = $("#pwd").val();
            $.ajax({
                type: "POST",
                url: "/index/authentification",
                data: { login: loginVal, pwd: pwdVal },
                success: function(data) {
                    var result = jQuery.parseJSON(data);
                    if(result.status == 'error') {
                        if(result.messages) {
                            ZendTremplin_addErrorAfter('login','error_login',result.messages.login ? result.messages.login : '');
                            ZendTremplin_addErrorAfter('pwd','error_pwd',result.messages.pwd ? result.messages.pwd : '');
                            ZendTremplin_addErrorAfter('submit','error_submit',result.messages.submit ? result.messages.submit : '');
                        }
                    }
                    else {
                        if(result.status == 'success' && result.redirect) {
                            $(location).attr('href',"/myspace");
                        }
                    }
                }
            });
            return false;
        });
    });
</script>
<script type="text/javascript">
    $(function() {
        $("#citySearch").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "http://api.geonames.org/searchJSON",
                    dataType: "jsonp",
                    data: { username: 'aleblond', name_startsWith : request.term, country : 'FR', maxRows: '10'},
                    success: function(data) {
                        response( $.map( data.geonames, function( item ) {
                            return {
                                label: item.name + ', ' +item.adminName1,
                                value: item.name
                            }
                        }));
                    }
                }); 
            }
        });
    });
</script>